﻿using System.Linq.Expressions;

namespace SharePoint.Orm.Helpers {
	internal class ExpressionTreeModifier : ExpressionVisitor {
		private readonly Expression _from;
		private readonly Expression _to;

		internal ExpressionTreeModifier(Expression from, Expression to) {
			_from = from;
			_to = to;
		}

		internal Expression CopyAndModify(Expression expression) {
			return this.Visit(expression);
		}

		protected override Expression Visit(Expression exp) {
			if (exp == _from) {
				return _to;
			}
			return base.Visit(exp);
		}
	}
}